<template>
	<view class="pwd-retrieve-container">
		<uni-forms ref="form" :value="data" labelWidth="80px">
			<uni-forms-item name="evaluateScore" label="评价打分" required>
				<uni-rate v-model="data.evaluateScore" @change="onChange" />
				<text style="color:#e43d33">{{ text }}</text>
			</uni-forms-item>
			<uni-forms-item name="evaluateContent" label="评价描述">
				<uni-easyinput type="textarea" v-model="data.evaluateContent" placeholder="请对本次服务进行评价" />
				</uni-forms-item>
			<button type="primary" size="default" @click="submit">提交</button>
		</uni-forms>
	</view>
</template>

<script>
import { evaluateOrder } from '@/api/business/order';

export default {
	data() {
		return {
			text: '',
			data: {
				evaluateScore: 0,
				evaluateContent: ''
			},
			rules: {
				evaluateScore: {
					rules: [
						{
							required: true,
							errorMessage: '请选择工单类型'
						},
						{
							validateFunction: function(rule, value, data, callback) {
								// console.log('rule', rule)
								// console.log('value', value)
								// console.log('data', data)
								if(value === 0){
									callback('请您为本次服务评价打分');
								}
							}
						}
					]
				}
			}
		};
	},
	onLoad(option) {
		// console.log('option', option)
		this.option = option;
	},
	onReady() {},
	methods: {
		submit() {
			this.$refs.form.validate().then(res => {
				if(this.data.evaluateScore === 0){
					// toast('请您为本次服务评价打分');
					uni.showToast({
					  icon: 'none',
					  title: '请您为本次服务评价打分'
					})
					return
				}
				let a = {
					id: this.option.id,
					evaluateScore: this.data.evaluateScore,
					evaluateContent: this.data.evaluateContent
				};
				evaluateOrder(a).then(response => {
					setTimeout(() => {
						uni.showToast({
							title: '评价成功'
						});
						setTimeout(() => {
							uni.hideToast();
							//关闭提示后跳转
							//'/pages/work/index'
							this.$tab.navigateBack();
							// this.$tab.redirectTo('/pages/work/index')
						}, 1000);
					}, 0);
				});
			});
		},
		onChange(e) {
			// console.info(e);
			if (e.value == 1) {
				this.text = '非常不满意';
			} else if (e.value == 2) {
				this.text = '不满意';
			} else if (e.value == 3) {
				this.text = '一般满意';
			} else if (e.value == 4) {
				this.text = '满意';
			} else if (e.value == 5) {
				this.text = '非常满意';
			}
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #ffffff;
}

.pwd-retrieve-container {
	padding-top: 36rpx;
	padding: 15px;
}

button {
	margin-top: 30rpx;
	margin-bottom: 30rpx;
}

.button-sp-area {
	margin: 0 auto;
	width: 60%;
}

.mini-btn {
	margin-right: 40rpx;
}
</style>
